// Excel表列名称

package Leetcode;

import java.util.ArrayList;
import java.util.List;

class Solution168_1 {
    public String convertToTitle(int columnNumber) {
        List<Integer> list = new ArrayList<>();
        while (columnNumber > 26) {
            if (columnNumber % 26 == 0) {
                list.add(26);
                columnNumber = columnNumber / 26 - 1;
            } else {
                list.add(columnNumber % 26);
                columnNumber /= 26;
            }
        }
        list.add(columnNumber);
        StringBuilder sb = new StringBuilder();
        for (int i = list.size() - 1; i >= 0; i--) {
            sb.append((char) (list.get(i) + 'A' - 1));
        }
        return sb.toString();
    }
}


class Solution168_2 {
    public String convertToTitle(int columnNumber) {
        StringBuilder sb = new StringBuilder();
        while (columnNumber != 0) {
            columnNumber--;
            sb.append((char)('A' + columnNumber % 26));
            columnNumber /= 26;
        }
        return sb.reverse().toString();
    }
}